clear all;

AD=load('AD.mat');
BE=load('BE.mat');
CF=load('CF.mat');

%% draw
fig=figure('Color',[1 1 1], 'Position',[20 50 1200 720]);

ah1 = axes('Parent',fig,'Units','normalized','Position',[0.09 0.5838 0.2134 0.3557]);
yyaxis left
plot(AD.x, AD.y_credit_ini, '-b' , 'LineWidth', 2 );
hold on
plot(AD.x, AD.y_credit_new, '--k' , 'LineWidth', 2 );
ylim([0,150]);
yticks(0:50:150);
ylabel('loan demand', 'FontSize',12,'Interpreter','Latex');
yyaxis right
plot(AD.x, AD.y_credit_gap, '-.r' , 'LineWidth', 2 );
title( 'A. Loan demand (vary $\Pi_{i,t}$)', 'FontSize',15,'Interpreter','Latex');
xlabel('market size $\Pi_{i,t}$', 'FontSize',12,'Interpreter','Latex');
ylabel('difference in loan demand', 'FontSize',12,'Interpreter','Latex');
legend('without branch','with branch','difference',...
    'interpreter','latex','location','northwest')
xlim([100,200]);
ylim([50,130]);
yticks(50:20:130);
set(gca,'FontSize',12);
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'r';

ah2 = axes('Parent',fig,'Units','normalized','Position',[0.41 0.5838 0.2134 0.3557]);
yyaxis left
plot(BE.x, BE.y_credit_ini, '-b' , 'LineWidth', 2 );
hold on
plot(BE.x, BE.y_credit_new, '--k' , 'LineWidth', 2 );
ylim([0,180]);
yticks(0:50:200);
ylabel('loan demand', 'FontSize',12,'Interpreter','Latex');
yyaxis right
plot(BE.x, BE.y_credit_gap, '-.r' , 'LineWidth', 2 );
title( 'B. Loan demand (vary $Z_i$)', 'FontSize',15,'Interpreter','Latex');
xlabel('market productivity $Z_i$', 'FontSize',12,'Interpreter','Latex');
ylabel('difference in loan demand', 'FontSize',12,'Interpreter','Latex');
legend('without branch','with branch','difference',...
    'interpreter','latex','location','northwest')
xlim([0.84,1.29]);
xticks(0.84:0.1:1.24);
ylim([30,150]);
yticks(30:30:150);
set(gca,'FontSize',12);
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'r';

ah3 = axes('Parent',fig,'Units','normalized','Position',[0.73 0.5838 0.2134 0.3557]);
plot(CF.x, CF.y_credit, '-b' , 'LineWidth', 2 );
title( 'C. Loan demand (vary $d_{i,t}$)', 'FontSize',15,'Interpreter','Latex');
xlabel('distance from the nearest branch $d_{i,t}$', 'FontSize',12,'Interpreter','Latex');
ylabel('loan demand', 'FontSize',12,'Interpreter','Latex');
xlim([0,30]);
ylim([0,110]);
yticks(0:25:100);
set(gca,'FontSize',12);

ah4 = axes('Parent',fig,'Units','normalized','Position',[0.09 0.1100 0.2134 0.3557]);
yyaxis left
plot(AD.x, AD.y_output_ini, '-b' , 'LineWidth', 2 );
hold on
plot(AD.x, AD.y_output_new, '--k' , 'LineWidth', 2 );
ylim([0,260]);
yticks(0:50:250);
ylabel('output', 'FontSize',12,'Interpreter','Latex');
yyaxis right
plot(AD.x, AD.y_output_gap, '-.r' , 'LineWidth', 2 );
title( 'D. Output (vary $\Pi_{i,t}$)', 'FontSize',15,'Interpreter','Latex');
xlabel('market size $\Pi_{i,t}$', 'FontSize',12,'Interpreter','Latex');
ylabel('difference in output', 'FontSize',12,'Interpreter','Latex');
legend('without branch','with branch','difference',...
    'interpreter','latex','location','northwest')
xlim([100,200]);
ylim([60,180]);
yticks(60:30:180);
set(gca,'FontSize',12);
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'r';

ah5 = axes('Parent',fig,'Units','normalized','Position',[0.41 0.1100 0.2134 0.3557]);
yyaxis left
plot(BE.x, BE.y_output_ini, '-b' , 'LineWidth', 2 );
hold on
plot(BE.x, BE.y_output_new, '--k' , 'LineWidth', 2 );
ylim([0,310]);
yticks(0:100:300);
ylabel('output', 'FontSize',12,'Interpreter','Latex');
yyaxis right
plot(BE.x, BE.y_output_gap, '-.r' , 'LineWidth', 2 );
title( 'E. Output (vary $Z_i$)', 'FontSize',15,'Interpreter','Latex');
xlabel('market productivity $Z_i$', 'FontSize',12,'Interpreter','Latex');
ylabel('difference in output', 'FontSize',12,'Interpreter','Latex');
legend('without branch','with branch','difference',...
    'interpreter','latex','location','northwest')
xlim([0.84,1.29]);
xticks(0.84:0.1:1.24);
ylim([50,200]);
yticks(50:50:200);
set(gca,'FontSize',12);
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'r';

ah6 = axes('Parent',fig,'Units','normalized','Position',[0.73 0.1100 0.2134 0.3557]);
plot(CF.x, CF.y_output, '-b' , 'LineWidth', 2 );
title( 'F. Output (vary $d_{i,t}$)', 'FontSize',15,'Interpreter','Latex');
xlabel('distance from the nearest branch $d_{i,t}$', 'FontSize',12,'Interpreter','Latex');
ylabel('output', 'FontSize',12,'Interpreter','Latex');
xlim([0,30]);
ylim([30,190]);
yticks(30:30:180);
set(gca,'FontSize',12);
